export interface ModelConfig {
  [key: string]: {
    apiKey: string;
    baseUrl: string;
    modelName: string;
    temperature?: number;
    maxTokens?: number;
  };
}

export const defaultModelConfig: ModelConfig = {
  DEEPSEEK_V3: {
    apiKey: '',
    baseUrl: 'https://api.deepseek.com/v1',
    modelName: 'deepseek-v3',
    temperature: 0.7,
    maxTokens: 2048
  }
};

export class ModelConfigReader {
  static async read(modelName: string) {
    try {
      // 使用IPC通信读取配置
      const config = await window.electronAPI.readModelConfig(modelName);
      if (config) {
        return config;
      }
    } catch (error) {
      // IPC通信错误，使用默认配置
    }
    
    const config = defaultModelConfig[modelName];
    if (!config) {
      throw new Error(`Model configuration not found for ${modelName}`);
    }
    return config;
  }
}

export class ModelConfigWriter {
  static async write(modelConfig: ModelConfig): Promise<void> {
    try {
      // 使用IPC通信写入配置
      const result = await window.electronAPI.writeModelConfig(modelConfig);
      if (!result.success) {
        throw new Error(result.error);
      }
    } catch (error) {
      throw new Error(`Failed to write model configuration: ${error instanceof Error ? error.message : String(error)}`);
    }
  }
}